<template>
  <div class="app-container">

    <!-- 搜索栏 -->
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="员工名称" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入员工名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="工号" prop="empNumber">
        <el-input
          v-model="queryParams.empNumber"
          placeholder="请输入工号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="身份证" prop="idCard">
        <el-input
          v-model="queryParams.idCard"
          placeholder="请输入身份证"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="电话" prop="phoneNumber">
        <el-input
          v-model="queryParams.phoneNumber"
          placeholder="请输入电话号码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>




    <el-table :data="tableData" :loading="loading" style="width: 100%;">
      <el-table-column label="员工编号" align="center" prop="userId" />
      <el-table-column label="员工名称" align="center" prop="name" />
      <el-table-column label="工号" align="center" prop="empNumber" />
      <el-table-column label="原部门" align="center" prop="dept.deptName" />
      <el-table-column label="用户性别" align="center" prop="sex">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_user_sex" :value="scope.row.sex" />
        </template>
      </el-table-column>
      <el-table-column label="身份证" align="center" prop="idCard">
        <template slot-scope="scope">
          <span>{{ scope.row.idCard || 'N/A' }}</span>
        </template>
      </el-table-column>
      <el-table-column label="身份证号地域" align="center" prop="idNumberRegion" />
      <el-table-column label="手机号码" align="center" prop="phoneNumber" />
      <el-table-column label="地域" align="center" prop="region" />
      <el-table-column label="合同签订时间" align="center" prop="contractDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.contractDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="合同截至日期" align="center" prop="contractLong" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.contractLong, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="入职时间" align="center" prop="date" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.date, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="入职类型" align="center" prop="typeOfEmployment">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.type_of_employment" :value="scope.row.typeOfEmployment" />
        </template>
      </el-table-column>
      <el-table-column label="人员类型" align="center" prop="typeOfMen">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.type_of_men" :value="scope.row.typeOfMen" />
        </template>
      </el-table-column>
      <el-table-column label="婚姻状态" align="center" prop="maritalStatus">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.marital_status" :value="scope.row.maritalStatus" />
        </template>
      </el-table-column>
      <el-table-column label="政治面貌" align="center" prop="politicalLandscape" />
      <el-table-column label="住址" align="center" prop="address" />
      <el-table-column label="最高学历" align="center" prop="highEducationalLevel" />
      <el-table-column label="毕业学校" align="center" prop="school" />
      <el-table-column label="专业" align="center" prop="major" />
      <el-table-column label="民族" align="center" prop="nation" />
      <el-table-column label="紧急联系人" align="center" prop="emergencyContact" />
      <el-table-column label="紧急联系人电话" align="center" prop="emergencyContactPhone" />
      <el-table-column label="第一学历" align="center" prop="firstDegree" />
      <el-table-column label="第二学历" align="center" prop="secondDegree" />
      <el-table-column label="学制类型" align="center" prop="typeEducation" />
      <el-table-column label="开户行" align="center" prop="bank" />
      <el-table-column label="银行账号" align="center" prop="bankAccountNumber" />
      <el-table-column label="爱好特长" align="center" prop="hobby" />
      <el-table-column label="是否安排寝室" align="center" prop="dormitoryNeed" />
      <el-table-column label="寝室号" align="center" prop="dormitory" />
      <el-table-column label="出生年月" align="center" prop="birthday" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.birthday, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="其他" align="center" prop="other" />
      <el-table-column label="预留字段1" align="center" prop="Reserved1" />
      <el-table-column label="预留字段2" align="center" prop="Reserved2" />
      <el-table-column label="预留字段3" align="center" prop="Reserved3" />
      <el-table-column label="预留字段4" align="center" prop="Reserved4" />
      <el-table-column label="预留字段5" align="center" prop="Reserved5" />
      <el-table-column label="预留字段6" align="center" prop="Reserved6" />
      <el-table-column label="预留字段7" align="center" prop="Reserved7" />
      <el-table-column label="预留字段8" align="center" prop="Reserved8" />
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { emplist } from "@/api/Empment/employed";

export default {
  name: "employed",
  dicts: ['marital_status', 'type_of_employment', 'type_of_men', 'sys_user_sex'],
  data() {
    return {
      tableData: [],
      loading: false,
      ids: [],
      single: true,
      deptName: undefined,
      deptOptions: undefined,
      multiple: true,
      showSearch: true,
      total: 0,
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        userId: null,
        name: null,
        deptId: null,
        empNumber: null,
        sex: null,
        idCard: null,
        idNumberRegion: null,
        phoneNumber: null,
        region: null,
        contractDate: null,
        contractLong: null,
        date: null,
        typeOfEmployment: null,
        typeOfMen: null,
        maritalStatus: null,
        politicalLandscape: null,
        address: null,
        highEducationalLevel: null,
        school: null,
        major: null,
        nation: null,
        emergencyContact: null,
        emergencyContactPhone: null,
        firstDegree: null,
        secondDegree: null,
        typeEducation: null,
        bank: null,
        bankAccountNumber: null,
        hobby: null,
        dormitoryNeed: null,
        dormitory: null,
        birthday: null,
        other: null,
        Reserved1: null,
        Reserved2: null,
        Reserved3: null,
        Reserved4: null,
        Reserved5: null,
        Reserved6: null,
        Reserved7: null,
        Reserved8: null
      },
      // 表单参数
      form: {},
      defaultProps: {
        children: "children",
        label: "label"
      }
    };
  },

  methods: {
    getList() {
      this.fetchData(); // 组件挂载后加载数据
    },

    fetchData() {
      this.loading = true;
      // 传递所有查询参数给 API
      emplist(this.queryParams)
        .then(response => {
          this.tableData = response.rows; // 从响应中获取数据并赋值给tableData
          this.loading = false;
          this.total = response.total;
        })
        .catch(error => {
          console.error("加载数据时出现错误:", error);
          this.loading = false;
        });
    },

    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1; // 搜索时从第一页开始
      this.getList();
    },

    /** 重置按钮操作 */
    resetQuery() {
      this.$refs.queryForm.resetFields(); // 重置表单
      this.queryParams = {
        pageNum: 1,
        pageSize: 10,
        userId: null,
        name: null,
        deptId: null,
        empNumber: null,
        sex: null,
        idCard: null,
        idNumberRegion: null,
        phoneNumber: null,
        region: null,
        contractDate: null,
        contractLong: null,
        date: null,
        typeOfEmployment: null,
        typeOfMen: null,
        maritalStatus: null,
        politicalLandscape: null,
        address: null,
        highEducationalLevel: null,
        school: null,
        major: null,
        nation: null,
        emergencyContact: null,
        emergencyContactPhone: null,
        firstDegree: null,
        secondDegree: null,
        typeEducation: null,
        bank: null,
        bankAccountNumber: null,
        hobby: null,
        dormitoryNeed: null,
        dormitory: null,
        birthday: null,
        other: null,
        Reserved1: null,
        Reserved2: null,
        Reserved3: null,
        Reserved4: null,
        Reserved5: null,
        Reserved6: null,
        Reserved7: null,
        Reserved8: null
      };
      this.getList(); // 重置后重新加载数据
    }
  },

  mounted() {
    this.fetchData(); // 组件挂载后加载数据
  }
};
</script>
